<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/view/common/common.jsp"%>
<style>
.none {
	display: none;
}
</style>
<div class="modal-dialog modal-lg" role="document">
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal"
				aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
			<h4 class="modal-title text-primary" id="myModalLabel">奖品信息编辑</h4>
		</div>
		<div class="modal-body">
			<div class="container-fluid">
				<form action="<c:url value='/prize/edit.json'/>" name="editForm" enctype="multipart/form-data"
							class="form-horizontal"  id="editForm" method="post">
				<div class="row">				
					<div class="col-md-12 col-xs-12">
					<div class="panel panel-primary">
							<div class="panel-heading">
								基本信息
							</div>
							<div class="panel-body">	
						
							<input type="hidden" name="prizeId" value="${parameter.entity.prizeId}">

								<div class="form-group">
									<label for="cjCode" class="col-sm-2 control-label">抽奖码</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="cjCode" tabIndex="13"
											   name="cjCode" value="${parameter.entity.cjCode}"
											   placeholder="抽奖码">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<div class="form-group">
									<label for="activityCode" class="col-sm-2 control-label">活动编号</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="activityCode" tabIndex="13"
											   name="activityCode" value="${parameter.entity.activityCode}"
											   placeholder="活动编号是唯一的每个活动的标识，eg：可以参考活动管理">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<div class="form-group">
									<label for="level" class="col-sm-2 control-label">奖项等级</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="level" tabIndex="13"
											   name="level" value="${parameter.entity.level}"
											   placeholder="奖项等级：eg: 一等奖">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

							<div class="form-group">
								<label disabled="true" for="name" class="col-sm-2 control-label">奖品主名称</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="name" tabIndex="13"
										name="name" value="${parameter.entity.name}"
										placeholder="奖品主名称：eg：养护一体茶">
								</div>
								<div class="col-md-4 col-xs-4 text-error"></div>
							</div>

								<div class="form-group">
									<label disabled="true" for="names" class="col-sm-2 control-label">奖品副信息</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="names" tabIndex="13"
											   name="names" value="${parameter.entity.names}"
											   placeholder="奖品副信息：eg：五盒">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<div class="form-group">
									<label for="number" class="col-sm-2 control-label">奖品数量</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="number" tabIndex="13"
											   name="number" value="${parameter.entity.number}"
											   placeholder="奖品数量：eg:600">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<div class="form-group">
									<label for="redeemCode" class="col-sm-2 control-label">兑换码</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="redeemCode" tabIndex="13"
											   name="redeemCode" value="${parameter.entity.redeemCode}"
											   placeholder="兑换码">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<div class="form-group">
									<label for="effeDateBegin" class="col-sm-2 control-label">有效开始日期</label>
									<div class="col-sm-8">
										<input type="date" class="form-control" id="effeDateBegin" tabIndex="13"
											   name="effeDateBegin" value="${parameter.entity.effeDateBegin}"
											   placeholder="兑换有效开始日期">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<div class="form-group">
									<label for="effeDateEnd" class="col-sm-2 control-label">有效结束日期</label>
									<div class="col-sm-8">
										<input type="date" class="form-control" id="effeDateEnd" tabIndex="13"
											   name="effeDateEnd" value="${parameter.entity.effeDateEnd}"
											   placeholder="兑换有效结束日期">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>
						</div>
						</div>
					</div>

				</div>
				</form>
			</div>
		</div>
		<div class="modal-footer">
			<div class="form-group">
				<div class="col-md-6 col-xs-12">
					<button type="button" class="btn btn-default btn-block quitBtn" tabIndex="26"
						id="quitBtn" data-dismiss="modal" name="quitBtn" value="login"
						tabindex="4" data-loading-text="正在返回......">
						<span class="glyphicon glyphicon-remove-sign">&nbsp;</span>关闭
					</button>
				</div>
				<div class="col-md-6 col-xs-12">
					<button type="button" class="btn btn-success btn-block" form="editForm" tabIndex="27"
						id="saveBtn" name="saveBtn" value="saveBtn" tabindex="4"
						data-loading-text="正在提交......">
						<span class="glyphicon glyphicon-save">&nbsp;</span>保存
					</button>
				</div>
			</div>
		</div>
	</div>
</div>


<jsp:include page="/WEB-INF/view/common/form.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		init();
		initRmLevel();
		rmLevel();
	});
	
	function rmLevel(){
		$(":radio").click(function(){
			  var type=$(this).val();
			  hideInput(type);
		});
	}
	
	function initRmLevel(){
		var type=$("input:radio:checked").val();
		if(type!=undefined){
			hideInput(type);
		}
		}
	
	function hideInput(type){
		  $("#levelTable tr.lc").each(function (){
				if($(this).attr("tag")!=type){
				$(this).find("input").attr("disabled","disabled"); 
				$(this).css("display","none");
				}else{
					$(this).find("input").removeAttr("disabled"); 
					$(this).css("display","");
				}
		  });
	}
	

	function init() {
		//$("#editName").focus().select();
		var btn = null;
		$("#editForm").validate({submitHandler : function(form) {
						$(form).ajaxSubmit({
									beforeSubmit : function(arr, $form, options) {
										btn.button("loading");
									},
									success : function(responseText,
											statusText, xhr, $form) {
										var m = $.parseJSON(xhr.responseText);
										btn.button("reset");
										if(m.flag=="0"){
											alert("保存成功");
										$(".quitBtn").click();
											$("#search").click();
                                            location.reload();
                                        }else{
											alert("保存失败");
										}
									},
									error : function(xhr, textStatus,
											errorThrown) {
										var m = $.parseJSON(xhr.responseText);
										btn.button("reset");
										alert("保存失败");
									}
								});
					},
					rules : {
                        activityId:{
                          	required:true
						},
						name : {
							required : true
						},
                        names : {
                            required : true
                        },
						activityId:{
							required: true
						},
                        level:{
                            required: true
                        },
                        number:{
                            required: true
                        },
                        redeemCode:{
                            required: true
                        }
					},
					onkeyup : false,
					messages : {
                        activityId:{
                          	required:"活动ID不能为空，可参考活动管理"
						},
						name : {
							required:"奖品主名称必须填写"
						},
                        names : {
                            required:"奖品副信息必须填写"
                        },
                        redeemCode:{
							required:"兑换码必须填写"
						},
                        number:{
                            required:"数量必须填"
                        },
                        level:{
                            required:"奖项必须填"
                        },
						activityId:{
						    required:"活动ID必须填写"
						}
					},
					focusInvalid : true,
					errorClass : "text-danger",
					validClass : "valid",
					errorElement : "small",
					errorPlacement : function(error, element) {
						error.appendTo(element.closest("div.form-group")
								.children("div.text-error"));
					}
				});
		$("#editForm").find("input[type='checkbox']").change(function(e){
			var $t=$(this);
			var next=$t.next("input[type='hidden']");
			$t.prop("checked")?next.val(1):next.val(0);
		});
		

	
		
		$("#saveBtn").click(function(e) {
			btn = $(this).button();
			$(document.forms["editForm"]).submit(); 
			/* $('#uploadModal').modal({
				backdrop : "static"
			});
			
			setInterval("getProgress()",1000); */
		});
	
		
	}

	
</script>
